﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>Entity Framework - MySql Integration</title>
    <link type="text/css" rel="stylesheet" href="bootstrap.min.css" />
</head>

<body>

    <div class="document-contents">

        <h3 id="DocIntroduction">Introduction</h3>
        <p>
            While our default templates designed to work with SQL Server, you can easily modify them to work with MySql. In order to do that, you need to follow below steps.</p>

		<h4>Download Project</h4>
	    <p>
       		Go to <a href="http://aspnetboilerplate.com/Templates">http://aspnetboilerplate.com/Templates</a> and download a new project. Select ASP.NET MVC 5.x tab and don't forget to select Entity Framework.
       	</p>
       	
       	<h4>Install MySql.Data.Entity</h4>
       	<p>Then you need to install <a href="https://www.nuget.org/packages/MySql.Data.Entity/">MySql.Data.Entity</a> nuget package to your <strong>.EntityFramework</strong> and <strong>.Web</strong> projects. Installing this nuget package to your <strong>.Web</strong> project should make necessary changes in your web.config file.</p>
       	<p>Open your DbContext's configuration class (Configuration.cs) and place below code in it's constructor</p>
       	<pre lang="cs">SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());</pre>

       	
       	<h4>Configure ConnectionString</h4>
       	<p>You need to change your connection string in the web.config file in order to work with your MySql database. An example connection string would be</p>
       	<pre lang="xml">&lt;add name="Default" connectionString="server=localhost;port=3306;database=sampledb;uid=root;password=***" providerName="MySql.Data.MySqlClient"/&gt;</pre>
       	
       	<h4>Re-generate migrations</h4>
       	<p>If you choose "Include module zero?" while downloading your startup template, there will be some migration files included in your project but those files are generated for Sql Server. Delete all migration files in your <strong>.EntityFramework</strong> project under Migrations folder. Migration files start with a timestamp. A migration file name would be like this "201506210746108_AbpZero_Initial"</p>
       	<p>After deleting all migration files, select your <strong>.Web</strong> project as startup project, open Visual Studio's Package Manager Console and select <strong>.EntityFramework</strong> project as default project in Package Manager Console. Then run below command to add migration for MySql.</p>
       	<pre lang="cs">Add-Migration "AbpZero_Initial"</pre>
       	<p>Now you can create your database using below command</p>
       	<pre lang="cs">Update-Database</pre>
       	
       	<p>It is all done, now you can run your project with MySql.</p>
    </div>
</body>

</html>